{% extends "base.html" %}
{% load i18n %}

{% block navigation %}
	<ul class="nav navbar-nav">
		<li class="active"><a href="{% url 'home' %}">Index</a></li>
		{% if user.is_authenticated %}
		  <li><a href="{% url 'import' %}">Import</a></li>
        {% endif %}
		<li>
		{% if user.is_authenticated %}
          <a href="{% url 'accounts_logout' %}" target="parent" title="Logout">{% trans "<< Logout >>" %}</a>
        {% else %}
          <a href="{% url 'accounts_login' %}" target="parent" title="Login">{% trans "<< Login >>" %}</a>
        {% endif %}
		</li>
	</ul>
{% endblock %}

{% block content %}

<!-- MAIN-CLASS BEGIN -->
    <div id="mainClassModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mainClassModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">

          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title" id="mainClassModalLabel">VN Class Editor - Primary data</h4>
          </div>
          <div class="modal-body">
            <form id="main_classform" class="form-horizontal" role="form" accept-charset="UTF-8" action="{% url 'data' %}" data-remote="true" method="post"> 
              {% csrf_token %}
              <input type="hidden" name="id" value="{{cls.id}}" />
              <input type="hidden" name="datatype" value="vnclass" />
              
              <div class="form-group">
                <label for="vnc_prefix" class="col-sm-2 control-label">Name</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="vnc_prefix" name="vnc_prefix" placeholder="Name" value="{{cls.prefix}}" />
                </div>
              </div>
              
              <div class="form-group">
                <label for="vnc_number" class="col-sm-2 control-label">Number</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="vnc_number" name="vnc_number" placeholder="Number" value="{{cls.number}}" />
                </div>
              </div>

              <div class="form-group">
                <div class="col-sm-2 text-right"><strong>Status</strong></div>
                <div class="col-sm-10"><span>{{cls.status}}</span></div>
              </div>

              <div class="form-group">
                <div class="col-sm-2 text-right"><strong>Version</strong></div>
                <div class="col-sm-10"><span>{{cls.version}}</span></div>
              </div>
              
              {% if cls.modified_by %}
              <div class="form-group">
                <div class="col-sm-2 text-right"><strong>Changed</strong></div>
                <div class="col-sm-10"><span> by {{cls.modified_by}}</span></div>
              </div>
              {% endif %}
              
            </form>
          </div>

          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
            <input class="btn btn-primary" name="commit" type="submit" value="Save" form="main_classform" />
          </div>          

        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
<!-- MAIN-CLASS END -->

<!-- UPD-LANGUAGE BEGIN -->
    <div id="addLangModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="addLangModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">

          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title" id="addLangModalLabel">Language Editor</h4>
          </div>
          <div class="modal-body">
            <form id="upd_langform" class="form-horizontal" role="form" accept-charset="UTF-8" action="{% url 'home' %}" data-remote="true" method="post"> 
              {% csrf_token %}
              <input type="hidden" id="id" name="id" value="" />
              <input type="hidden" name="datatype" value="language" />

              <div class="form-group">
                <label for="value" class="col-sm-2 control-label">Code</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="value" name="value" placeholder="Language code by ISO 639-3" value="" />
                </div>
              </div>

              <div class="form-group">
                <label for="name" class="col-sm-2 control-label">Name</label>
                <div class="col-sm-10">
				  <input type="text" class="form-control" id="name" name="name" placeholder="language name in English" value="" />
                </div>
              </div>

            </form>
          </div>

          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
            <input class="btn btn-primary" name="commit" type="submit" value="Save" form="upd_langform" />
          </div>          

        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
<!-- UPD-LANGUAGE END -->

<section class="cols">
  <div class="row">
    <div class="col-md-4">
      {% if languages %}
      <form class="form-horizontal" role="form" id="frm1" action="{% url 'home' %}" method="post" > {% csrf_token %}
        <div class="form-group">
          <label for="lang">{% trans "Active language" %}:</label>
          <select class="form-control" id="lang" name="lang" onchange="this.form.submit()">
		  {% for l in languages %}
		    <option value="{{ l.value }}" {% if l.value == sel_lang %} selected="selected" {% endif %} > {% trans l.name %} </option>
		  {% endfor %}
		  </select>
		  {% if user.is_authenticated %}
		    <button class="ibtn btn-sm open-addLangModal" data-toggle="modal" data-target="#addLangModal" data-id="0"><span class="glyphicon glyphicon-plus"></span></button>
          {% endif %}
		</div>
      </form>
      {% endif %}
    </div>
    <div class="col-md-4">
      {% if datatype %}
      <form class="form-horizontal" role="form" id="frm2" action="{% url 'home' %}" method="post" > {% csrf_token %}
        <div class="form-group">
          <label for="dtype">{% trans "Visible data" %}:</label>
          <select class="form-control" id="dtype" name="dtype" onchange="this.form.submit()">
		  {% for t in datatype %}
		    <option value="{{ t.value }}" {% if t.value == sel_dtype %} selected="selected" {% endif %} > {% trans t.name %} </option>
		  {% endfor %}
		  </select>
		  {% if user.is_authenticated %}
		    <button class="ibtn btn-sm open-addMainClassModal" data-toggle="modal" data-target="#mainClassModal" data-id="0"><span class="glyphicon glyphicon-plus"></span></button>
          {% endif %}
		</div>
      </form>
      {% endif %}
    </div>
    <div class="col-md-4"></div>
  </div>
</section>

{% for l in data %}
<div class="row">
  <div class="col-md-6">{% if l.f_url != "" %} <a href="{% url 'data' %}?id={{l.f_url}}" target="parent"> {% endif %}{{l.f_cell}}{% if l.f_url != "" %}</a>{% endif %}</div>
  <div class="col-md-6">{% if l.s_url != "" %} <a href="{% url 'data' %}?id={{l.s_url}}" target="parent"> {% endif %}{{l.s_cell}}{% if l.s_url != "" %}</a>{% endif %}</div>
</div>
{% endfor %}

{% endblock %}

{% block footer %}
<p class="text-center credit"></p>
{% endblock %}